<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="Vue">
    <meta name="description" content="C# | Web | html | python |">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
	<meta name="baidu-site-verification" content="code-c9IEbSDR1U" />

	
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>vue初学注意 | X-Y-Z`s Blog</title>
	
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>
    <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>
<meta name="generator" content="Hexo 5.4.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>



   <style>
    body{
       background-image: url(/medias/background.JPG);
       background-repeat:no-repeat;
       background-size:cover;
       background-attachment:fixed;
    }
</style>



<body  onload="opener.location.reload()">

	
    <header class="navbar-fixed">

<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?b3593488200a34a873defcaa11fc888a";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">X-Y-Z`s Blog</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="" class="waves-effect waves-light">

      
      <i class="fas fa-sitemap" style="zoom: 0.6;"></i>
      
      <span>归类</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/categories">
          
          <i class="fas fa-bookmark" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>分类</span>
        </a>
      </li>
      
      <li>
        <a href="/archives">
          
          <i class="fas fa-archive" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>归档</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/navigate" class="waves-effect waves-light">
      
      <i class="fas fa-location-arrow" style="zoom: 0.6;"></i>
      
      <span>导航</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/about" class="waves-effect waves-light">
      
      <i class="fas fa-user-circle" style="zoom: 0.6;"></i>
      
      <span>关于</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友链</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">X-Y-Z`s Blog</div>
        <div class="logo-desc">
            
            C# | Web | html | python |
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-sitemap"></i>
			
			归类
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>

                  <a href="/categories " style="margin-left:50px">
				  
				   <i class="fa fas fa-bookmark" style="position: absolute;left:28px" ></i>
			      
		          <span>分类</span>
                  </a>
                </li>
              
                <li>

                  <a href="/archives " style="margin-left:50px">
				  
				   <i class="fa fas fa-archive" style="position: absolute;left:28px" ></i>
			      
		          <span>归档</span>
                  </a>
                </li>
              
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/navigate" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-location-arrow"></i>
			
			Navigate
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/about" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-user-circle"></i>
			
			关于
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/blinkfox/hexo-theme-matery" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork He
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #4e9ef5;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/blinkfox/hexo-theme-matery" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork He" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/12.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">vue初学注意</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

	.toc-widget.card.toc-fixed {
    opacity: 0.85;
	}
    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
		height: 500px;
		overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }
    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Vue/">
                                <span class="chip bg-color">Vue</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                    <div class="post-cate">
                        <i class="fas fa-bookmark fa-fw icon-category"></i>
                        
                            <a href="/categories/Vue/" class="post-category">
                                Vue
                            </a>
                        
                    </div>
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-12-26
                </div>
                

                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-check fa-fw"></i>更新日期:&nbsp;&nbsp;
                    2022-03-27
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    4.8k
                </div>
                

                
                <div class="info-break-policy">
                    <i class="far fa-clock fa-fw"></i>阅读时长:&nbsp;&nbsp;
                    23 分
                </div>
                

                
            </div>
        </div>
        <hr class="clearfix">

        

        
        <!-- 代码块折行 -->
        <style type="text/css">
            code[class*="language-"], pre[class*="language-"] { white-space: pre-wrap !important; }
        </style>
        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h3 id="1-调试没有-vm-data问题"><a href="#1-调试没有-vm-data问题" class="headerlink" title="1. 调试没有 vm.$data问题"></a>1. 调试没有 vm.$data问题</h3><p>假设定义 vue 对象 如下。</p>
<figure class="highlight javascript"><table><tbody><tr><td class="code"><pre class=" language-hljs javascript"><span class="hljs-keyword">var</span> vm = Vue.createApp({<br>    <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {<br>        <span class="hljs-keyword">return</span> {<br>            <span class="hljs-attr">price</span>: <span class="hljs-number">10</span>,<br>        };<br>    },<br>    <span class="hljs-attr">template</span>: <span class="hljs-string">`	价格：&lt;input type="number" v-model="price" /&gt;`</span>,<br>}).mount(<span class="hljs-string"><code class="language-hljs javascript"><span class="hljs-keyword">var</span> vm = Vue.createApp({<br>    <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {<br>        <span class="hljs-keyword">return</span> {<br>            <span class="hljs-attr">price</span>: <span class="hljs-number">10</span>,<br>        };<br>    },<br>    <span class="hljs-attr">template</span>: <span class="hljs-string">`	价格：&lt;input type="number" v-model="price" /&gt;`</span>,<br>}).mount(<span class="hljs-string">"#app"</span>)<br></code></pre></td></tr></tbody></table></figure>



<p>vue 运行后调试的话原本可以通过 vm.$加对应项查看变量。如图)</p>
<img src="https://gitee.com/blogofxyz/blog-photo/raw/master/blog/Vue/vm.$object.png" alt="image-20211226182226019" style="zoom: 80%;">

<p>但某次我的就莫名其妙没有了。 变成这样</p>
<img src="https://gitee.com/blogofxyz/blog-photo/raw/master/blog/Vue/vm.$nothing.png" alt="image-20211226182340471" style="zoom:80%;">

<p>原因如下，定义的时候如果是上边代码的形式，是可以查看的。但是，如果是先声明后绑定的话。就没法查看了。</p>
<p><mark>不能查看</mark>的初始化例子如下：</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre class=" language-hljs js"><span class="hljs-keyword">var</span> vm = Vue.createApp({<br>    <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {<br>        <span class="hljs-keyword">return</span> {<br>            <span class="hljs-attr">price</span>: <span class="hljs-number">10</span>,<br>        };<br>    },<br>    <span class="hljs-attr">template</span>: <span class="hljs-string">`	价格：&lt;input type="number" v-model="price" /&gt;`</span>,<br>});<br>vm.mount(<span class="hljs-string"><code class="language-hljs js"><span class="hljs-keyword">var</span> vm = Vue.createApp({<br>    <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {<br>        <span class="hljs-keyword">return</span> {<br>            <span class="hljs-attr">price</span>: <span class="hljs-number">10</span>,<br>        };<br>    },<br>    <span class="hljs-attr">template</span>: <span class="hljs-string">`	价格：&lt;input type="number" v-model="price" /&gt;`</span>,<br>});<br>vm.mount(<span class="hljs-string">"#app"</span>)<br></code></pre></td></tr></tbody></table></figure>



<p><mark>可以查看的初始化例子 </mark> 如下</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript"><span class="hljs-keyword">var</span> vm = Vue.createApp({</span><br><span class="javascript">    <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">        <span class="hljs-keyword">return</span> {</span><br><span class="javascript">            <span class="hljs-attr">price</span>: <span class="hljs-number">10</span>,</span><br><span class="javascript">        };</span><br><span class="javascript">    },</span><br><span class="javascript">    <span class="hljs-attr">template</span>: <span class="hljs-string">`	价格：&lt;input type="number" v-model="price" /&gt;`</span>,</span><br><span class="javascript">}).mount(<span class="hljs-string">"#app"</span>)</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript"><span class="hljs-keyword">var</span> vm = Vue.createApp({</span><br><span class="javascript">    <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">        <span class="hljs-keyword">return</span> {</span><br><span class="javascript">            <span class="hljs-attr">price</span>: <span class="hljs-number">10</span>,</span><br><span class="javascript">        };</span><br><span class="javascript">    },</span><br><span class="javascript">    <span class="hljs-attr">template</span>: <span class="hljs-string">`	价格：&lt;input type="number" v-model="price" /&gt;`</span>,</span><br><span class="javascript">}).mount(<span class="hljs-string">"#app"</span>)</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<p>或者先创建变量，然后在另外赋值绑定。</p>
<p>代码如下。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const vv = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        data() {</span></span><br><span class="xml"><span class="handlebars">            return {</span></span><br><span class="xml"><span class="handlebars">                list: ["1532", "8465321"],</span></span><br><span class="xml"><span class="handlebars">                term: '',</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars">        methods: {</span></span><br><span class="xml"><span class="handlebars">            newValue() {</span></span><br><span class="xml"><span class="handlebars">                this.list.push(this.term);</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars"></span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"term"</span> /&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-comment">&lt;!-- 添加一个数据 --&gt;</span></span></span><br><span class="xml"><span class="handlebars"></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">v-on:click</span>=<span class="hljs-string">"newValue"</span>&gt;</span> 添加 <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars"></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span> <span class="hljs-comment">&lt;!-- 显示添加后的数据 --&gt;</span></span></span><br><span class="xml"><span class="handlebars">                <span class="hljs-tag">&lt;<span class="hljs-name">my-li</span> </span></span></span><br><span class="hljs-tag"><span class="xml"><span class="handlebars">                <span class="hljs-attr">v-for</span>=<span class="hljs-string">"(item,index) of list"</span></span></span></span><br><span class="hljs-tag"><span class="xml"><span class="handlebars">                <span class="hljs-attr">v-bind:liItem</span>=<span class="hljs-string">"item"</span></span></span></span><br><span class="hljs-tag"><span class="xml"><span class="handlebars">                <span class="hljs-attr">v-bind:liIndex</span>=<span class="hljs-string">"index"</span>/&gt;</span></span></span><br><span class="xml"><span class="handlebars">  		  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    </span></span><br><span class="xml"><span class="handlebars">    //添加一个组件</span></span><br><span class="xml"><span class="handlebars">    vv.component("my-li", {</span></span><br><span class="xml"><span class="handlebars">        props: ['liItem', 'liIndex'],</span></span><br><span class="xml"><span class="handlebars">        template: `<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>第</span><span class="hljs-template-variable">{{<span class="hljs-name">liIndex</span>}}</span><span class="xml">号姐姐:</span><span class="hljs-template-variable">{{<span class="hljs-name">liItem</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>`</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    </span></span><br><span class="xml"><span class="handlebars">    const vm=vv.mount("#app")</span></span><br><span class="xml"><span class="handlebars">    //在赋值绑定，查看时用 vm 查看</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const vv = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        data() {</span></span><br><span class="xml"><span class="handlebars">            return {</span></span><br><span class="xml"><span class="handlebars">                list: ["1532", "8465321"],</span></span><br><span class="xml"><span class="handlebars">                term: '',</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars">        methods: {</span></span><br><span class="xml"><span class="handlebars">            newValue() {</span></span><br><span class="xml"><span class="handlebars">                this.list.push(this.term);</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars"></span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">v-model</span>=<span class="hljs-string">"term"</span> /&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-comment">&lt;!-- 添加一个数据 --&gt;</span></span></span><br><span class="xml"><span class="handlebars"></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">v-on:click</span>=<span class="hljs-string">"newValue"</span>&gt;</span> 添加 <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars"></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span> <span class="hljs-comment">&lt;!-- 显示添加后的数据 --&gt;</span></span></span><br><span class="xml"><span class="handlebars">                <span class="hljs-tag">&lt;<span class="hljs-name">my-li</span> </span></span></span><br><span class="hljs-tag"><span class="xml"><span class="handlebars">                <span class="hljs-attr">v-for</span>=<span class="hljs-string">"(item,index) of list"</span></span></span></span><br><span class="hljs-tag"><span class="xml"><span class="handlebars">                <span class="hljs-attr">v-bind:liItem</span>=<span class="hljs-string">"item"</span></span></span></span><br><span class="hljs-tag"><span class="xml"><span class="handlebars">                <span class="hljs-attr">v-bind:liIndex</span>=<span class="hljs-string">"index"</span>/&gt;</span></span></span><br><span class="xml"><span class="handlebars">  		  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    </span></span><br><span class="xml"><span class="handlebars">    //添加一个组件</span></span><br><span class="xml"><span class="handlebars">    vv.component("my-li", {</span></span><br><span class="xml"><span class="handlebars">        props: ['liItem', 'liIndex'],</span></span><br><span class="xml"><span class="handlebars">        template: `<span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span>第</span><span class="hljs-template-variable">{{<span class="hljs-name">liIndex</span>}}</span><span class="xml">号姐姐:</span><span class="hljs-template-variable">{{<span class="hljs-name">liItem</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>`</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    </span></span><br><span class="xml"><span class="handlebars">    const vm=vv.mount("#app")</span></span><br><span class="xml"><span class="handlebars">    //在赋值绑定，查看时用 vm 查看</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>





<h3 id="2-计算属性-amp-侦听器"><a href="#2-计算属性-amp-侦听器" class="headerlink" title="2.计算属性 &amp; 侦听器"></a>2.计算属性 &amp; 侦听器</h3><h4 id="2-1计算属性-amp-侦听器区别"><a href="#2-1计算属性-amp-侦听器区别" class="headerlink" title="2.1计算属性 &amp; 侦听器区别"></a>2.1计算属性 &amp; 侦听器区别</h4><p>两种都可检测data里数值的变化。然后做出一些反应。</p>
<p>区别：</p>
<table>
<thead>
<tr>
<th>区别项</th>
<th>computed</th>
<th>watch</th>
</tr>
</thead>
<tbody><tr>
<td>页面渲染时是否执行</td>
<td>yes</td>
<td>no</td>
</tr>
<tr>
<td>局限</td>
<td>必须返回一个东西</td>
<td>必须侦听某一变量</td>
</tr>
<tr>
<td>执行时期</td>
<td>页面渲染到此属性时</td>
<td>侦听值发生变化时</td>
</tr>
</tbody></table>
<h4 id="2-2-侦听属性监测对象的属性"><a href="#2-2-侦听属性监测对象的属性" class="headerlink" title="2.2 侦听属性监测对象的属性"></a>2.2 侦听属性监测对象的属性</h4><p>字段：</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre class=" language-hljs js"><span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span>{<br>    <span class="hljs-attr">return</span>:{<br>        <span class="hljs-attr">search</span>:{<br>            <span class="hljs-attr">searchPhone</span>:<span class="hljs-string"><code class="language-hljs js"><span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span>{<br>    <span class="hljs-attr">return</span>:{<br>        <span class="hljs-attr">search</span>:{<br>            <span class="hljs-attr">searchPhone</span>:<span class="hljs-string">""</span>,<br>        },<br>    }<br>}<br></code></pre></td></tr></tbody></table></figure>

<p>侦听器：</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre class=" language-hljs js">watch:{<br>    <span class="hljs-string">"search.searchPhone"</span>(oldValue,newValue){<br>        <span class="hljs-keyword">if</span>(oldValue!==newValue){<br>			<span class="hljs-built_in">console</span>.log(<span class="hljs-string"><code class="language-hljs js">watch:{<br>    <span class="hljs-string">"search.searchPhone"</span>(oldValue,newValue){<br>        <span class="hljs-keyword">if</span>(oldValue!==newValue){<br>			<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"不同"</span>);<br>        }<br>    },<br>}<br></code></pre></td></tr></tbody></table></figure>

<h3 id="3-v-if-amp-v-show"><a href="#3-v-if-amp-v-show" class="headerlink" title="3. v-if &amp; v-show"></a>3. v-if &amp; v-show</h3><h4 id="3-1-v-if"><a href="#3-1-v-if" class="headerlink" title="3.1 v-if"></a>3.1 v-if</h4><p>渲染时通过变量或者表达式判断是否渲染绑定的标签或模块。</p>
<p>当值发生变化后，重新渲染某一模块。</p>
<h4 id="3-2-v-show"><a href="#3-2-v-show" class="headerlink" title="3.2 v-show"></a>3.2 v-show</h4><p>通过一个bool变量或表达式决定一个标签或者模块的是否显示。</p>
<p>当bool变量或者表达式的值发生变化后，改变 display 使其显示。</p>
<table>
<thead>
<tr>
<th>区别</th>
<th>v-if</th>
<th>v-show</th>
</tr>
</thead>
<tbody><tr>
<td><code>HTML</code> 中是否存在</td>
<td>不存在</td>
<td>dislay：none隐藏</td>
</tr>
<tr>
<td>渲染时间</td>
<td>指定判别式或变量为true时</td>
<td>第一次页面渲染时</td>
</tr>
</tbody></table>
<h3 id="4-计算属性添加参数"><a href="#4-计算属性添加参数" class="headerlink" title="4. 计算属性添加参数"></a>4. 计算属性添加参数</h3><p>原来计算属性格式为</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre class=" language-hljs js">computed:{<br>    <span class="hljs-function"><span class="hljs-title">getValue</span>(<span class="hljs-params"></span>)</span>{<br>        <span class="hljs-keyword"><code class="language-hljs js">computed:{<br>    <span class="hljs-function"><span class="hljs-title">getValue</span>(<span class="hljs-params"></span>)</span>{<br>        <span class="hljs-keyword">return</span> value;         <br>    }<br>}<br></code></pre></td></tr></tbody></table></figure>

<p>如果在<code>getValue</code>的括号里添加参数是会报错的。</p>
<p>可以结合计算属性的表面原理来改变下（真实原理还没理解）。</p>
<p>计算属性就是返回一个值。这个返回逻辑我们不知道怎么修改，可以对这个返回的值做手脚，比如我们再给他写一个函数，让它返回到这个函数里边继续去执行就行了。</p>
<p>格式如下。</p>
<figure class="highlight js"><table><tbody><tr><td class="code"><pre class=" language-hljs js">computed: {<br>    <span class="hljs-function"><span class="hljs-title">getClass</span>(<span class="hljs-params"></span>)</span> {<br>        <span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">xy</span>)=&gt;</span> {<br>            <span class="hljs-comment">//加上你的逻辑</span><br>            <span class="hljs-keyword"><code class="language-hljs js">computed: {<br>    <span class="hljs-function"><span class="hljs-title">getClass</span>(<span class="hljs-params"></span>)</span> {<br>        <span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">xy</span>)=&gt;</span> {<br>            <span class="hljs-comment">//加上你的逻辑</span><br>            <span class="hljs-keyword">return</span> newValue<br>        };<br>    },<br>},<br></code></pre></td></tr></tbody></table></figure>

<p>当然，箭头函数也可以换成别的<code>function</code>，或者已经定义的函数。</p>
<p>引用时如下</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">:class</span>=<span class="hljs-string">"getClass(x)"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"bpp"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-comment"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">:class</span>=<span class="hljs-string">"getClass(x)"</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"bpp"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><span class="hljs-comment"><!--x为变量或值--></span><br></code></pre></td></tr></tbody></table></figure>

<h3 id="5-组件定义的方法"><a href="#5-组件定义的方法" class="headerlink" title="5.组件定义的方法"></a>5.组件定义的方法</h3><h4 id="5-1-向vue对象中添加"><a href="#5-1-向vue对象中添加" class="headerlink" title="5.1 向vue对象中添加"></a>5.1 向vue对象中添加</h4><p>步骤：先初始化<code>vue</code>对象，然后向这个对象中添加组件。</p>
<p>示例代码如下：</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> pp = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;sb /&gt;`</span>,</span><br><span class="javascript">    });</span><br><span class="javascript">    pp.component(<span class="hljs-string">"sb"</span>, {</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;h2&gt;here are a sb!&lt;/h2&gt;`</span>,</span><br><span class="javascript">    });</span><br><span class="javascript">    <span class="hljs-keyword">const</span> vm = pp.mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> pp = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;sb /&gt;`</span>,</span><br><span class="javascript">    });</span><br><span class="javascript">    pp.component(<span class="hljs-string">"sb"</span>, {</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;h2&gt;here are a sb!&lt;/h2&gt;`</span>,</span><br><span class="javascript">    });</span><br><span class="javascript">    <span class="hljs-keyword">const</span> vm = pp.mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<blockquote>
<p>​        最后重新定义<code>vm</code>的原因是方便调试。可以参考本文 1 中内容。不需要的话可直接在<code>app</code>的最后进行<code>mount()</code></p>
</blockquote>
<h4 id="5-2-vue对象引入"><a href="#5-2-vue对象引入" class="headerlink" title="5.2 vue对象引入"></a>5.2 vue对象引入</h4><p>这种方法需要先定义组件，然后在初始化<code>vue</code>对象时引入这些组件。</p>
<p>​        示例代码如下：</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> sb = {</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;h2&gt;here are a sb!&lt;/h2&gt;`</span>,</span><br><span class="javascript">    };</span><br><span class="javascript">    <span class="hljs-keyword">const</span> pp = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">components</span>: {</span><br><span class="javascript">            sb,</span><br><span class="javascript">            <span class="hljs-string">"s-p"</span>: sb,</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;sb /&gt;&lt;s-p/&gt;`</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> sb = {</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;h2&gt;here are a sb!&lt;/h2&gt;`</span>,</span><br><span class="javascript">    };</span><br><span class="javascript">    <span class="hljs-keyword">const</span> pp = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">components</span>: {</span><br><span class="javascript">            sb,</span><br><span class="javascript">            <span class="hljs-string">"s-p"</span>: sb,</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;sb /&gt;&lt;s-p/&gt;`</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<h4 id="5-3初始化时定义"><a href="#5-3初始化时定义" class="headerlink" title="5.3初始化时定义"></a>5.3初始化时定义</h4><p>这种方法是在vue对象初始化时在其内部直接定义，不过，少的话还行，多的话代码就臃肿了。</p>
<p>​        示例代码如下：</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> pp = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">components</span>: {</span><br><span class="javascript">            <span class="hljs-attr">sb</span>:{</span><br><span class="javascript">                <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;h2&gt;here are a sb!&lt;/h2&gt;`</span>,</span><br><span class="javascript">            },</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;sb /&gt;`</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> pp = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">components</span>: {</span><br><span class="javascript">            <span class="hljs-attr">sb</span>:{</span><br><span class="javascript">                <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;h2&gt;here are a sb!&lt;/h2&gt;`</span>,</span><br><span class="javascript">            },</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`&lt;sb /&gt;`</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<h3 id="6-组件传值-props"><a href="#6-组件传值-props" class="headerlink" title="6. 组件传值 (props)"></a>6. 组件传值 (<code>props</code>)</h3><p>父组件可通过属性，参数，传递数据给子组件。也可以通过路由等（我还不会）。</p>
<p>子组件可以选择接受，或拒收。</p>
<h4 id="6-1-接收"><a href="#6-1-接收" class="headerlink" title="6.1 接收"></a>6.1 接收</h4><h5 id="6-1-1-参数传值"><a href="#6-1-1-参数传值" class="headerlink" title="6.1.1 参数传值"></a>6.1.1 参数传值</h5><blockquote>
<div style="color:yellow;whitespace:pre;font-size:1.5rem;line-height:3rem">        html 大小写不敏感，如果组件内参数为驼峰命名法，则需要用横杠替换法（每个大写都替换为横杠加对应的小写。）</div>
</blockquote>
<p>父组件调用子组件，可直接在标签内声明属性，并赋值，也可通过参数向子组件传递参数。</p>
<ul>
<li><p>通过参数接收。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app=Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">template</span>:</span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;child message="what's a good day!"&gt;&lt;/child&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    })</span><br><span class="javascript">    app.component(<span class="hljs-string">"child"</span>,{</span><br><span class="javascript">        <span class="hljs-attr">props</span>:[<span class="hljs-string">"message"</span>],</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">conL</span>(<span class="hljs-params"></span>)</span>{</span><br><span class="javascript">                <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.message);</span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;h2 @click="conL"&gt;{{message}}&lt;/h2&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>)</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app=Vue.createApp({</span><br><span class="javascript">        <span class="hljs-attr">template</span>:</span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;child message="what's a good day!"&gt;&lt;/child&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    })</span><br><span class="javascript">    app.component(<span class="hljs-string">"child"</span>,{</span><br><span class="javascript">        <span class="hljs-attr">props</span>:[<span class="hljs-string">"message"</span>],</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">conL</span>(<span class="hljs-params"></span>)</span>{</span><br><span class="javascript">                <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.message);</span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;h2 @click="conL"&gt;{{message}}&lt;/h2&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>)</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<p>通过参数传来的值，是无法进行修改的，如果想修改，只能进行备份。</p>
<blockquote>
<p>子组件传递参数，或者修改父组件中的值可参考本文<code>9--emit</code> 的内容。</p>
</blockquote>
<p>如下：</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    app.component("clickAdd_2", {</span></span><br><span class="xml"><span class="handlebars">        props: ["counter_son"],</span></span><br><span class="xml"><span class="handlebars">        data() {</span></span><br><span class="xml"><span class="handlebars">            return {</span></span><br><span class="xml"><span class="handlebars">                here_counter:this.counter_son,</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars">        template:</span></span><br><span class="xml"><span class="handlebars">        `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>双向奔赴<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">here_counter</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"here_counter++"</span>&gt;</span>点我+1<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">		`,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    app.component("clickAdd_2", {</span></span><br><span class="xml"><span class="handlebars">        props: ["counter_son"],</span></span><br><span class="xml"><span class="handlebars">        data() {</span></span><br><span class="xml"><span class="handlebars">            return {</span></span><br><span class="xml"><span class="handlebars">                here_counter:this.counter_son,</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars">        template:</span></span><br><span class="xml"><span class="handlebars">        `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>双向奔赴<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">here_counter</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">"here_counter++"</span>&gt;</span>点我+1<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">		`,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure></li>
</ul>
<h5 id="6-1-2-属性传值"><a href="#6-1-2-属性传值" class="headerlink" title="6.1.2 属性传值"></a>6.1.2 属性传值</h5><figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app=Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template:</span></span><br><span class="xml"><span class="handlebars">        `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">child</span> <span class="hljs-attr">message</span>=<span class="hljs-string">"what's a good day!"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color:red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">child</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `</span></span><br><span class="xml"><span class="handlebars">    })</span></span><br><span class="xml"><span class="handlebars">    app.component("child",{</span></span><br><span class="xml"><span class="handlebars">        template: </span></span><br><span class="xml"><span class="handlebars">        `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">this.$attrs.msg</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `</span></span><br><span class="xml"><span class="handlebars">    }).mount("#app")</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app=Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template:</span></span><br><span class="xml"><span class="handlebars">        `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">child</span> <span class="hljs-attr">message</span>=<span class="hljs-string">"what's a good day!"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color:red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">child</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `</span></span><br><span class="xml"><span class="handlebars">    })</span></span><br><span class="xml"><span class="handlebars">    app.component("child",{</span></span><br><span class="xml"><span class="handlebars">        template: </span></span><br><span class="xml"><span class="handlebars">        `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">this.$attrs.msg</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `</span></span><br><span class="xml"><span class="handlebars">    }).mount("#app")</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<p>在这个例子中，<code>style</code>会直接继承给 <code>h2</code>，</p>
<blockquote>
<p>​      </p>
<p>​     如果子模板中有多个标签，且没有根元素，则style属性默认将没人继承。</p>
<p>​     如果子模板有多个并列标签，可通过以下方式进行获取。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">child</span> <span class="hljs-attr">message</span>=<span class="hljs-string">"what's a good day!"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color:red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">child</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app.component("child", {</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">:style</span>=<span class="hljs-string">"$attrs.style"</span>&gt;</span>4865313<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">:style</span>=<span class="hljs-string">"$attrs.style"</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `,</span></span><br><span class="xml"><span class="handlebars"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">child</span> <span class="hljs-attr">message</span>=<span class="hljs-string">"what's a good day!"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color:red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">child</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app.component("child", {</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">:style</span>=<span class="hljs-string">"$attrs.style"</span>&gt;</span>4865313<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">:style</span>=<span class="hljs-string">"$attrs.style"</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    `,</span></span><br><span class="xml"><span class="handlebars">    }).mount("#app");</span></span><br></code></pre></td></tr></tbody></table></figure>


</blockquote>
<h5 id="6-1-3-子组件拒收"><a href="#6-1-3-子组件拒收" class="headerlink" title="6.1.3 子组件拒收"></a>6.1.3 子组件拒收</h5><p>可在模板定义时指定<code>inheritAttrs</code> 属性为<code>false</code>。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">child</span> <span class="hljs-attr">message</span>=<span class="hljs-string">"what's a good day!"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color:red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">child</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app</span></span><br><span class="xml"><span class="handlebars">        .component("child", {</span></span><br><span class="xml"><span class="handlebars">        inheritAttrs: false,</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>4865313<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    })</span></span><br><span class="xml"><span class="handlebars">        .mount("#app");</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">child</span> <span class="hljs-attr">message</span>=<span class="hljs-string">"what's a good day!"</span> <span class="hljs-attr">style</span>=<span class="hljs-string">"color:red"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">child</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app</span></span><br><span class="xml"><span class="handlebars">        .component("child", {</span></span><br><span class="xml"><span class="handlebars">        inheritAttrs: false,</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>4865313<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">$attrs.message</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    })</span></span><br><span class="xml"><span class="handlebars">        .mount("#app");</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<p>​         </p>
<p>​        此时 子模块 <code>div</code> 将不继承style属性。如果<code>inherittAttrs</code>为<code>true</code>，则将继承（此属性默认为<code>true</code>）。</p>
<p>​        但是又会发现，下边的<code>message</code>属性仍然显示了，所以这个值得改变并不能影响这种方法的获取，即子模版不能<code>嘴上说不要，身体又很诚实</code>。</p>
<h3 id="7-vue-样式绑定的方法"><a href="#7-vue-样式绑定的方法" class="headerlink" title="7. vue 样式绑定的方法"></a>7. vue 样式绑定的方法</h3><h4 id="7-1-一般方法"><a href="#7-1-一般方法" class="headerlink" title="7.1 一般方法"></a>7.1 一般方法</h4><p>声明模板时给标签添加<mark><code>id</code></mark>或者<mark>样式类</mark>等信息，然后在<code>css</code>文件或者<code>style</code>标签中写样式。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myStyle</span>: <span class="hljs-string">"color:red;text-decoration:line-through"</span>,</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :style="myStyle"&gt;这怎么还有一个BUG&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myStyle</span>: <span class="hljs-string">"color:red;text-decoration:line-through"</span>,</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :style="myStyle"&gt;这怎么还有一个BUG&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>



<h4 id="7-2-data中写style"><a href="#7-2-data中写style" class="headerlink" title="7.2 data中写style"></a>7.2 data中写style</h4><p>在<code>vue</code>的<code>data</code>属性中声明一个<code>style</code>变量并赋值然后将此变量用<code>v-model</code>绑定至标签上。</p>
<p>代码如下：</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myStyle</span>: <span class="hljs-string">"color:red;text-decoration:line-through"</span>,</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :style="myStyle"&gt;asdsadsad&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myStyle</span>: <span class="hljs-string">"color:red;text-decoration:line-through"</span>,</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :style="myStyle"&gt;asdsadsad&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<h4 id="7-3-在data中把样式类定义为变量。"><a href="#7-3-在data中把样式类定义为变量。" class="headerlink" title="7.3 在data中把样式类定义为变量。"></a>7.3 在data中把样式类定义为变量。</h4><p>这种也需要在<code>css</code>文件或者<code>style</code>标签中已经写好样式类。</p>
<p>用<code>v-model</code>将值绑定至属性上。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myClassRed</span>:<span class="hljs-string">"red"</span>,</span><br><span class="javascript">                <span class="hljs-attr">myClassGreen</span>:<span class="hljs-string">"green"</span>,</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :class="myClassRed"&gt;asdsadsad&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myClassRed</span>:<span class="hljs-string">"red"</span>,</span><br><span class="javascript">                <span class="hljs-attr">myClassGreen</span>:<span class="hljs-string">"green"</span>,</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :class="myClassRed"&gt;asdsadsad&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<h4 id="7-4-样式类对象"><a href="#7-4-样式类对象" class="headerlink" title="7.4 样式类对象"></a>7.4 样式类对象</h4><p>同样需要先写样式。</p>
<h5 id="7-4-1-true-amp-false"><a href="#7-4-1-true-amp-false" class="headerlink" title="7.4.1 true &amp; false"></a>7.4.1 true &amp; false</h5><p>在<code>data</code>中把需要的样式写为一个对象，然后根据需要设置<code>true</code>与<code>false</code>。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">css</span>: {</span><br><span class="javascript">                    <span class="hljs-attr">transition</span>: <span class="hljs-literal">true</span>,</span><br><span class="javascript">                    <span class="hljs-attr">red</span>: <span class="hljs-literal">true</span>,</span><br><span class="javascript">                    <span class="hljs-attr">green</span>: <span class="hljs-literal">false</span>,</span><br><span class="javascript">                },</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">switch_bt</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.css.red = <span class="hljs-built_in">this</span>.css.green;</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.css.green = !<span class="hljs-built_in">this</span>.css.red;</span><br><span class="javascript">            },</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;span :class="css"&gt;everything is ok&lt;/span&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">        &lt;button @click="switch_bt"&gt;switch&lt;/button&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">css</span>: {</span><br><span class="javascript">                    <span class="hljs-attr">transition</span>: <span class="hljs-literal">true</span>,</span><br><span class="javascript">                    <span class="hljs-attr">red</span>: <span class="hljs-literal">true</span>,</span><br><span class="javascript">                    <span class="hljs-attr">green</span>: <span class="hljs-literal">false</span>,</span><br><span class="javascript">                },</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">switch_bt</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.css.red = <span class="hljs-built_in">this</span>.css.green;</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.css.green = !<span class="hljs-built_in">this</span>.css.red;</span><br><span class="javascript">            },</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;span :class="css"&gt;everything is ok&lt;/span&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">        &lt;button @click="switch_bt"&gt;switch&lt;/button&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<p>渲染时，会先对对象中的值判断，为true时才会加入到<code>classlist</code>中。</p>
<h5 id="7-4-2-指定值"><a href="#7-4-2-指定值" class="headerlink" title="7.4.2 指定值"></a>7.4.2 指定值</h5><p>与7.2类似，只不过看着更直观，同样也是写成一个对象。</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myStyle</span>:{</span><br><span class="javascript">                    <span class="hljs-attr">color</span>:<span class="hljs-string">"red"</span>,</span><br><span class="javascript">                    <span class="hljs-string">"text-decoration"</span>:<span class="hljs-string">"line-through"</span>  </span><br><span class="javascript">                },</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :style="myStyle"&gt;asdsadsad&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">myStyle</span>:{</span><br><span class="javascript">                    <span class="hljs-attr">color</span>:<span class="hljs-string">"red"</span>,</span><br><span class="javascript">                    <span class="hljs-string">"text-decoration"</span>:<span class="hljs-string">"line-through"</span>  </span><br><span class="javascript">                },</span><br><span class="javascript">            };</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">          &lt;div :style="myStyle"&gt;asdsadsad&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span>,</span><br><span class="javascript">    }).mount(<span class="hljs-string">"#app"</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<p>注意：如果某一个属性有横线，则必须用引号引起来，没有横线的话引号可以省略。</p>
<h3 id="8-事件修饰符"><a href="#8-事件修饰符" class="headerlink" title="8.  事件修饰符"></a>8.  事件修饰符</h3><p><code>self</code>；<code>prevent</code>；<code>capture</code>；<code>once</code></p>
<p><code>self</code> :点标签自己有用，子标签没用，</p>
<p><code>prevent</code>：清除默认事件，如form的提交。</p>
<p><code>catpure</code>：使事件从父标签至字标签执行。（默认顺序为从内到外）。</p>
<p><code>once</code>：只执行一次。<br>。。。等<br>官方地址：<a target="_blank" rel="noopener" href="https://v3.cn.vuejs.org/guide/events.html#%E4%BA%8B%E4%BB%B6%E4%BF%AE%E9%A5%B0%E7%AC%A6">传送门</a></p>
<h3 id="9-emit"><a href="#9-emit" class="headerlink" title="9. emit"></a>9. emit</h3><p>第一次学真的有点懵，不过敲完代码，跑出来效果后，理解的就多了点。</p>
<p>先说下原理，与<code>props</code> 传参类似。只不过，<code>props</code> 传的是父组件的值，而emit是传递的函数。</p>
<blockquote>
<p><b style="color:red">！</b> 父组件传函数时需要跟其他函数一样使用 @ 符号。<b style="color:red">！</b></p>
</blockquote>
<blockquote>
<p>生成这个组件的对象时，把父组件的某一个函数指定给它，而它通过emits属性接受。同props接受变量一样。然后子组件就可以 <mark style="border-radius:10px;padding:3px">调用</mark> 父组件的这个函数了。</p>
<p>之所以说是调用，是因为，如果你在 父组件这个函数的声明时有使用<mark style="border-radius:10px;padding:3px">父组件data的变量</mark>，那么，子组件调用仍然可以正常使用。</p>
</blockquote>
<p>一个代码实例:</p>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">counter</span>: <span class="hljs-string">"I have nothing!"</span>,      </span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">clickAdd</span>(<span class="hljs-params">st</span>)</span>{</span><br><span class="javascript">                <span class="hljs-built_in">console</span>.log(st);</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.counter+=st;</span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>:</span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">                父数据&lt;a&gt;{{counter}}&lt;/a&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">                &lt;button @click="clickAdd('father_Click')"&gt;老父亲的点击&lt;/button&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">                子数据&lt;child @emitAdd="clickAdd" :cou="counter"&gt;&lt;/child&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    })</span><br><span class="javascript">    app.component(<span class="hljs-string">"child"</span>,{</span><br><span class="javascript">        <span class="hljs-attr">props</span>:[<span class="hljs-string">"cou"</span>,<span class="hljs-string">"Add"</span>],</span><br><span class="javascript">        <span class="hljs-attr">emits</span>:[<span class="hljs-string">"emitAdd"</span>],</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {<span class="hljs-attr">counter</span>:<span class="hljs-built_in">this</span>.cou}</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">sonToFather</span>(<span class="hljs-params">value</span>)</span>{</span><br><span class="javascript">                <span class="hljs-built_in">console</span>.log(value);</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.$emit(<span class="hljs-string">"emitAdd"</span>,value)</span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        接受的：&lt;a&gt;{{cou}}&lt;/a&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">        	&lt;button @click='sonToFather("son_Click")'&gt;来自子组件的点击&lt;/button&gt;</span></span><br><span class="hljs-string"><span class="javascript">    	&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    })</span><br><span class="javascript">    <span class="hljs-keyword">const</span> vm=app.mount(<span class="hljs-string">'#app'</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript"></span><br><span class="javascript">    <span class="hljs-keyword">const</span> app = Vue.createApp({</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {</span><br><span class="javascript">                <span class="hljs-attr">counter</span>: <span class="hljs-string">"I have nothing!"</span>,      </span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">clickAdd</span>(<span class="hljs-params">st</span>)</span>{</span><br><span class="javascript">                <span class="hljs-built_in">console</span>.log(st);</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.counter+=st;</span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>:</span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">                父数据&lt;a&gt;{{counter}}&lt;/a&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">                &lt;button @click="clickAdd('father_Click')"&gt;老父亲的点击&lt;/button&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">                子数据&lt;child @emitAdd="clickAdd" :cou="counter"&gt;&lt;/child&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    })</span><br><span class="javascript">    app.component(<span class="hljs-string">"child"</span>,{</span><br><span class="javascript">        <span class="hljs-attr">props</span>:[<span class="hljs-string">"cou"</span>,<span class="hljs-string">"Add"</span>],</span><br><span class="javascript">        <span class="hljs-attr">emits</span>:[<span class="hljs-string">"emitAdd"</span>],</span><br><span class="javascript">        <span class="hljs-function"><span class="hljs-title">data</span>(<span class="hljs-params"></span>)</span> {</span><br><span class="javascript">            <span class="hljs-keyword">return</span> {<span class="hljs-attr">counter</span>:<span class="hljs-built_in">this</span>.cou}</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">methods</span>: {</span><br><span class="javascript">            <span class="hljs-function"><span class="hljs-title">sonToFather</span>(<span class="hljs-params">value</span>)</span>{</span><br><span class="javascript">                <span class="hljs-built_in">console</span>.log(value);</span><br><span class="javascript">                <span class="hljs-built_in">this</span>.$emit(<span class="hljs-string">"emitAdd"</span>,value)</span><br><span class="javascript">            }</span><br><span class="javascript">        },</span><br><span class="javascript">        <span class="hljs-attr">template</span>: </span><br><span class="javascript">        <span class="hljs-string">`</span></span><br><span class="hljs-string"><span class="javascript">        &lt;div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        接受的：&lt;a&gt;{{cou}}&lt;/a&gt;&lt;br&gt;</span></span><br><span class="hljs-string"><span class="javascript">        	&lt;button @click='sonToFather("son_Click")'&gt;来自子组件的点击&lt;/button&gt;</span></span><br><span class="hljs-string"><span class="javascript">    	&lt;/div&gt;</span></span><br><span class="hljs-string"><span class="javascript">        `</span></span><br><span class="javascript">    })</span><br><span class="javascript">    <span class="hljs-keyword">const</span> vm=app.mount(<span class="hljs-string">'#app'</span>);</span><br><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<blockquote>
<p>在这段代码中父组件声明一个<code>child</code> 标签，然后传给他<code>counter</code>，<code>clickAdd</code> ，<code>child</code>分别使用<code>props</code>、<code>emits</code>接收。</p>
</blockquote>
<blockquote>
<p>在父组件中，<code>clickAdd</code>函数是默认把<code>counter</code>字符串加<code>father_Click</code> 。但定义的函数是将一个参数加在<code>counter</code>后边，所以在子组件中，我们就可以传入这个参数。</p>
</blockquote>
<blockquote>
<p>就是在子组件中在声明一个函数——<code>sonToFather</code>。在这个函数体内就可以调用传入的函数——<code>clickAdd</code>，并指定传入这个函数的参数。这样子组件执行<code>sonToFather</code> 就等效是父组件的这个函数了。</p>
</blockquote>
<p>以此实现子组件对父组件值得修改。</p>
<h3 id="10-slot"><a href="#10-slot" class="headerlink" title="10. slot"></a>10. slot</h3><ul>
<li><p><code>slot</code> 插槽一般写法。</p>
<p>​        插槽，在子模板中声明一个位置，然后填充父组件传入的数据（字符串、对象、<code>html</code>代码等）。当子模板slot中有数据等东西时，是默认值，即当父组件啥都没传入时才会显示。</p>
<blockquote>
<p>​        当<mark>子模板有多个插槽</mark>时，需要声明<code>slot</code>的<code>name</code>属性，然后在父组件使用时指定值。格式如第一个代码块第7、10行。第二种为省略写法。</p>
<p>​        但是当使用的是第二个代码块的方法时，必须带上<code>default=</code>,如第二个代码块第12行。</p>
<p>​        当<mark>父组件中出现多个插槽</mark>的使用时，需要使用<code>template</code>标签。然后在<code>template</code>标签内指定<code>name</code>。</p>
</blockquote>
<p>示例代码如下。</p>
</li>
</ul>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">                <span class="hljs-tag">&lt;<span class="hljs-name">template</span> <span class="hljs-attr">v-slot:first</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">                	<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第二首歌：好好过 - 胡歌<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    		   <span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>                </span></span><br><span class="xml"><span class="handlebars">                <span class="hljs-tag">&lt;<span class="hljs-name">template</span> #<span class="hljs-attr">second</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">                	<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第二首歌：一念执着 - 胡歌/阿兰<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    		   <span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;/<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app.component("person", {</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"first"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第一首歌：我们的纪念 - 李雅微<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"second"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第二首歌：父亲 - 筷子兄弟<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	  <span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"third"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第三首歌：Letting GO - 蔡健雅<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    const vm = app.mount("#app");</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">                <span class="hljs-tag">&lt;<span class="hljs-name">template</span> <span class="hljs-attr">v-slot:first</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">                	<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第二首歌：好好过 - 胡歌<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    		   <span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span>                </span></span><br><span class="xml"><span class="handlebars">                <span class="hljs-tag">&lt;<span class="hljs-name">template</span> #<span class="hljs-attr">second</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">                	<span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第二首歌：一念执着 - 胡歌/阿兰<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    		   <span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;/<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app.component("person", {</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"first"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第一首歌：我们的纪念 - 李雅微<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"second"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第二首歌：父亲 - 筷子兄弟<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	  <span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"third"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>第三首歌：Letting GO - 蔡健雅<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;/<span class="hljs-name">slot</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    const vm = app.mount("#app");</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<ul>
<li><p>slot简写</p>
<p>这种简写算是都没有声明<code>name</code>的情况。</p>
<p>这里第一次使用时用到了一个知识点<mark>对象解构赋值</mark>，其作用是将子组件传来的对象还是啥都变成值。同时，也可以设定默认值如下代码块第6行。</p>
<blockquote>
<p>如果不解构，name输出的可能是个类。当然加<code>.valueName</code>也行。（valueName为类中项的名称）</p>
</blockquote>
<p>代码如下：</p>
</li>
</ul>
<figure class="highlight html"><table><tbody><tr><td class="code"><pre class=" language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">person</span> <span class="hljs-attr">v-slot</span>=<span class="hljs-string">"{song:item='未收录'}"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">              <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">item</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  </span></span><br><span class="xml"><span class="handlebars">    	    <span class="hljs-tag">&lt;/<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        还可以缩写呦!<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">person</span> #<span class="hljs-attr">default</span>=<span class="hljs-string">"{song:item='未收录'}"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">              <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">item</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  </span></span><br><span class="xml"><span class="handlebars">    	    <span class="hljs-tag">&lt;/<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">   	    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app.component("person", {</span></span><br><span class="xml"><span class="handlebars">        data() {</span></span><br><span class="xml"><span class="handlebars">            return {</span></span><br><span class="xml"><span class="handlebars">                songs: [</span></span><br><span class="xml"><span class="handlebars">                    "第一首歌：我们的纪念 - 李雅微",</span></span><br><span class="xml"><span class="handlebars">                    "第二首歌：父亲 - 筷子兄弟",</span></span><br><span class="xml"><span class="handlebars">                    "第三首歌：Letting GO - 蔡健雅",</span></span><br><span class="xml"><span class="handlebars">                    undefined</span></span><br><span class="xml"><span class="handlebars">                ],</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"song in songs"</span> <span class="hljs-attr">:song</span>=<span class="hljs-string">"song"</span> /&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    const vm = app.mount("#app");</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name"><code class="language-hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"app"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="handlebars"><span class="xml"></span></span><br><span class="xml"><span class="handlebars">    const app = Vue.createApp({</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">person</span> <span class="hljs-attr">v-slot</span>=<span class="hljs-string">"{song:item='未收录'}"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">              <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">item</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  </span></span><br><span class="xml"><span class="handlebars">    	    <span class="hljs-tag">&lt;/<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        还可以缩写呦!<span class="hljs-tag">&lt;<span class="hljs-name">br</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">            <span class="hljs-tag">&lt;<span class="hljs-name">person</span> #<span class="hljs-attr">default</span>=<span class="hljs-string">"{song:item='未收录'}"</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">              <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span><span class="hljs-template-variable">{{<span class="hljs-name">item</span>}}</span><span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  </span></span><br><span class="xml"><span class="handlebars">    	    <span class="hljs-tag">&lt;/<span class="hljs-name">person</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">   	    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">        `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    app.component("person", {</span></span><br><span class="xml"><span class="handlebars">        data() {</span></span><br><span class="xml"><span class="handlebars">            return {</span></span><br><span class="xml"><span class="handlebars">                songs: [</span></span><br><span class="xml"><span class="handlebars">                    "第一首歌：我们的纪念 - 李雅微",</span></span><br><span class="xml"><span class="handlebars">                    "第二首歌：父亲 - 筷子兄弟",</span></span><br><span class="xml"><span class="handlebars">                    "第三首歌：Letting GO - 蔡健雅",</span></span><br><span class="xml"><span class="handlebars">                    undefined</span></span><br><span class="xml"><span class="handlebars">                ],</span></span><br><span class="xml"><span class="handlebars">            }</span></span><br><span class="xml"><span class="handlebars">        },</span></span><br><span class="xml"><span class="handlebars">        template: `</span></span><br><span class="xml"><span class="handlebars">        <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          <span class="hljs-tag">&lt;<span class="hljs-name">slot</span> <span class="hljs-attr">v-for</span>=<span class="hljs-string">"song in songs"</span> <span class="hljs-attr">:song</span>=<span class="hljs-string">"song"</span> /&gt;</span></span></span><br><span class="xml"><span class="handlebars">    	<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span></span><br><span class="xml"><span class="handlebars">          `,</span></span><br><span class="xml"><span class="handlebars">    });</span></span><br><span class="xml"><span class="handlebars">    const vm = app.mount("#app");</span></span><br><span class="xml"><span class="handlebars"></span></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>></span><br></code></pre></td></tr></tbody></table></figure>

<h3 id="ERROE"><a href="#ERROE" class="headerlink" title="ERROE"></a><mark style="color:red;border-radius:10px;padding:5px">ERROE</mark></h3><h4 id="1-1"><a href="#1-1" class="headerlink" title="1.1"></a>1.1</h4><img src="https://gitee.com/blogofxyz/blog-photo/raw/master/blog/vue/error/error1.jpg" alt="img" style="zoom: 50%;">

<p>问题：子组件试图修改父组件传进来的值。</p>
<p>解决：可在父组件中声明一个方法，在方法中修改这个值，然后将这个方法通过emit传给子组件。</p>
<p>图片来源：<a target="_blank" rel="noopener" href="https://blog.csdn.net/github_35549695/article/details/82770044">turboemily的博客-CSDN博客</a></p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">张小白</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://blogofxyz.top/2021/12/26/vue%E5%88%9D%E5%AD%A6%E6%B3%A8%E6%84%8F/">https://blogofxyz.top/2021/12/26/vue%E5%88%9D%E5%AD%A6%E6%B3%A8%E6%84%8F/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">张小白</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Vue/">
                                    <span class="chip bg-color">Vue</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="qq,qzone,wechat,weibo" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    
    <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid="></script>
    <div class="addthis_inline_share_toolbox"></div>
    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.png" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    
        <style>
    .valine-card {
        margin: 1.5rem auto;
    }

    .valine-card .card-content {
        padding: 20px 20px 5px 20px;
    }

    #vcomments textarea {
        box-sizing: border-box;
        background: url("/medias/comment_bg.JPG") 100% 100% no-repeat;
	    color: white;
    opacity: 0.8;
    font-size: 18px;
    }

    #vcomments p {
        margin: 2px 2px 10px;
        font-size: 1.05rem;
        line-height: 1.78rem;
    }

    #vcomments blockquote p {
        text-indent: 0.2rem;
    }

    #vcomments a {
        padding: 0 2px;
        color: #4cbf30;
        font-weight: 500;
        text-decoration: none;
    }

    #vcomments img {
        max-width: 100%;
        height: auto;
        cursor: pointer;
    }

    #vcomments ol li {
        list-style-type: decimal;
    }

    #vcomments ol,
    ul {
        display: block;
        padding-left: 2em;
        word-spacing: 0.05rem;
    }

    #vcomments ul li,
    ol li {
	text-indent:2rem;
        display: list-item;
        line-height: 2.2rem;
        font-size: 1rem;
    }

    #vcomments ul li {
        list-style-type: disc;
    }

    #vcomments ul ul li {
        list-style-type: circle;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    #vcomments table, th, td {
        border: 0;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments h1 {
        font-size: 1.85rem;
        font-weight: bold;
        line-height: 2.2rem;
    }

    #vcomments h2 {
        font-size: 1.65rem;
        font-weight: bold;
        line-height: 1.9rem;
    }

    #vcomments h3 {
        font-size: 1.45rem;
        font-weight: bold;
        line-height: 1.7rem;
    }

    #vcomments h4 {
        font-size: 1.25rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    #vcomments h5 {
        font-size: 1.1rem;
        font-weight: bold;
        line-height: 1.4rem;
    }

    #vcomments h6 {
        font-size: 1rem;
        line-height: 1.3rem;
    }

    #vcomments p {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    #vcomments hr {
        margin: 12px 0;
        border: 0;
        border-top: 1px solid #ccc;
    }

    #vcomments blockquote {
        margin: 15px 0;
        border-left: 5px solid #42b983;
        padding: 1rem 0.8rem 0.3rem 0.8rem;
        color: #666;
        background-color: rgba(66, 185, 131, .1);
    }

    #vcomments pre {
        font-family: monospace, monospace;
        padding: 1.2em;
        margin: .5em 0;
        background: #272822;
        overflow: auto;
        border-radius: 0.3em;
        tab-size: 4;
    }

    #vcomments code {
        font-family: monospace, monospace;
        padding: 1px 3px;
        font-size: 0.92rem;
        color: #e96900;
        background-color: #f8f8f8;
        border-radius: 2px;
    }

    #vcomments pre code {
        font-family: monospace, monospace;
        padding: 0;
        color: #e8eaf6;
        background-color: #272822;
    }

    #vcomments pre[class*="language-"] {
        padding: 1.2em;
        margin: .5em 0;
    }

    #vcomments code[class*="language-"],
    pre[class*="language-"] {
        color: #e8eaf6;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }

    #vcomments b,
    strong {
        font-weight: bold;
    }

    #vcomments dfn {
        font-style: italic;
    }

    #vcomments small {
        font-size: 85%;
    }

    #vcomments cite {
        font-style: normal;
    }

    #vcomments mark {
        background-color: #fcf8e3;
        padding: .2em;
    }

    #vcomments table, th, td {
        padding: 12px 13px;
        border: 1px solid #dfe2e5;
    }

    table tr:nth-child(2n), thead {
        background-color: #fafafa;
    }

    #vcomments table th {
        background-color: #f2f2f2;
        min-width: 80px;
    }

    #vcomments table td {
        min-width: 80px;
    }

    #vcomments [type="checkbox"]:not(:checked), [type="checkbox"]:checked {
        position: inherit;
        margin-left: -1.3rem;
        margin-right: 0.4rem;
        margin-top: -1px;
        vertical-align: middle;
        left: unset;
        visibility: visible;
    }
	.v[data-class="v"] .vwrap .vheader .vinput {
		width: 32%;
		border-bottom: 1px dashed #dedede;
	}
</style>

<div class="card valine-card" data-aos="fade-up">
    <div class="comment_headling" style="font-size: 20px; font-weight: 700; position: relative; padding-left: 20px; top: 15px; padding-bottom: 5px;">
        <i class="fas fa-comments fa-fw" aria-hidden="true"></i>
        <span>评论</span>
    </div>
    <div id="vcomments" class="card-content" style="display: grid">
    </div>
</div>

<script src="/libs/valine/av-min.js"></script>
<script src="/libs/valine/Valine.min.js"></script>
<script>
	let metaPlaceholder = {"nick":"昵称/QQ号(必填)","mail":"邮箱(必填)","link":"网址(https://)"} ;
	
	new Valine({
			el: '#vcomments',
			appId: 'ghConjcbp7CpCRHJFPIRDdd2-gzGzoHsz',
			appKey: 'XnhsRQe0DKrPj7X8NnqYg6BX',
			notify: 'true' === 'true',
			verify: 'true' === 'true',
			visitor: 'true' === 'true',
			avatar: 'identicon',
			pageSize: '10',
			lang: 'zh-CN',
			placeholder: '有事不怕打扰，如果较急，可使用右侧反馈快速接受。',
			meta: ["y-nick", "e-mail", "your-link"],
			recordIP: 'true' === 'true',
			enableQQ: 'identicon',
			requiredFields: ["721850218d5dfa3e2ad5b3ac5a69dad8"],
			master: ["721850218d5dfa3e2ad5b3ac5a69dad8"],
			friends: ["4802978b7156ffcf24b571b35c594ad7"],
			tagMeta: ["发文地", "认识地", "过路地"],
			metaPlaceholder: metaPlaceholder,
		});
</script>

<!--酷Q推送-->


    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2022/01/01/%E6%B5%8F%E8%A7%88%E5%99%A8%E5%B1%8F%E8%94%BD%E5%8F%B3%E9%94%AE%E8%8F%9C%E5%8D%95%E5%8A%9F%E8%83%BD/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/15.jpg" class="responsive-img" alt="浏览器屏蔽右键菜单功能">
                        
                        <span class="card-title">浏览器屏蔽右键菜单功能</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            屏蔽浏览器默认的右键出现菜单的功能。
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2022-01-01
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/HTML/" class="post-category">
                                    HTML
                                </a>
                            
                            <a href="/categories/HTML/JavaScript/" class="post-category">
                                    JavaScript
                                </a>
                            
                            <a href="/categories/HTML/JavaScript/Vue/" class="post-category">
                                    Vue
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/HTML/">
                        <span class="chip bg-color">HTML</span>
                    </a>
                    
                    <a href="/tags/Vue/">
                        <span class="chip bg-color">Vue</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2021/12/17/HTML%E5%A1%8C%E9%99%B7/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/14.jpg" class="responsive-img" alt="HTML塌陷">
                        
                        <span class="card-title">HTML塌陷</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            HTML高度塌陷说明与解决方法
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2021-12-17
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-bookmark fa-fw icon-category"></i>
                            
                            <a href="/categories/HTML/" class="post-category">
                                    HTML
                                </a>
                            
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/CSS/">
                        <span class="chip bg-color">CSS</span>
                    </a>
                    
                    <a href="/tags/HTML/">
                        <span class="chip bg-color">HTML</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>


<script>
    $('#articleContent').on('copy', function (e) {
        // IE8 or earlier browser is 'undefined'
        if (typeof window.getSelection === 'undefined') return;

        var selection = window.getSelection();
        // if the selection is short let's not annoy our users.
        if (('' + selection).length < Number.parseInt('120')) {
            return;
        }

        // create a div outside of the visible area and fill it with the selected text.
        var bodyElement = document.getElementsByTagName('body')[0];
        var newdiv = document.createElement('div');
        newdiv.style.position = 'absolute';
        newdiv.style.left = '-99999px';
        bodyElement.appendChild(newdiv);
        newdiv.appendChild(selection.getRangeAt(0).cloneContents());

        // we need a <pre> tag workaround.
        // otherwise the text inside "pre" loses all the line breaks!
        if (selection.getRangeAt(0).commonAncestorContainer.nodeName === 'PRE' || selection.getRangeAt(0).commonAncestorContainer.nodeName === 'CODE') {
            newdiv.innerHTML = "<pre>" + newdiv.innerHTML + "</pre>";
        }

        var url = document.location.href;
        newdiv.innerHTML += '<br />'
            + '来源: X-Y-Z`s Blog<br />'
            + '文章作者: Zhang-little-white<br />'
            + '文章链接: <a href="' + url + '">' + url + '</a><br />'
            + '本文章著作权归作者所有，任何形式的转载都请注明出处。';

        selection.selectAllChildren(newdiv);
        window.setTimeout(function () {bodyElement.removeChild(newdiv);}, 200);
    });
</script>


<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('2'),
            headingSelector: 'h1,h2, h3, h4, h5'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h1,h2, h3, h4, h5').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    

    <div class="container row center-align"
         style="margin-bottom: 15px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2021-2022</span>
            
            <span id="year">2021</span>
            <a href="/about" target="_blank">Zhang-little-white</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/blinkfox/hexo-theme-matery" target="_blank">Matery</a>
            <br>
            
                &nbsp;<i class="fas fa-chart-area"></i>&nbsp;站点总字数:&nbsp;<span
                        class="white-color">53.2k</span>
            
            
            
            
            
            <br>

            <!-- 运行天数提醒. -->
            
                <span id="sitetime"> Loading ...</span>
                <script>
                    var calcSiteTime = function () {
                        var seconds = 1000;
                        var minutes = seconds * 60;
                        var hours = minutes * 60;
                        var days = hours * 24;
                        var years = days * 365;
                        var today = new Date();
                        var startYear = "2021";
                        var startMonth = "8";
                        var startDate = "12";
                        var startHour = "0";
                        var startMinute = "0";
                        var startSecond = "0";
                        var todayYear = today.getFullYear();
                        var todayMonth = today.getMonth() + 1;
                        var todayDate = today.getDate();
                        var todayHour = today.getHours();
                        var todayMinute = today.getMinutes();
                        var todaySecond = today.getSeconds();
                        var t1 = Date.UTC(startYear, startMonth, startDate, startHour, startMinute, startSecond);
                        var t2 = Date.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);
                        var diff = t2 - t1;
                        var diffYears = Math.floor(diff / years);
                        var diffDays = Math.floor((diff / days) - diffYears * 365);

                        // 区分是否有年份.
                        var language = 'zh-CN';
                        if (startYear === String(todayYear)) {
                            document.getElementById("year").innerHTML = todayYear;
                            var daysTip = 'This site has been running for ' + diffDays + ' days';
                            if (language === 'zh-CN') {
                                daysTip = '本站已运行 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                daysTip = '本站已運行 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = daysTip;
                        } else {
                            document.getElementById("year").innerHTML = startYear + " - " + todayYear;
                            var yearsAndDaysTip = 'This site has been running for ' + diffYears + ' years and '
                                + diffDays + ' days';
                            if (language === 'zh-CN') {
                                yearsAndDaysTip = '本站已运行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            } else if (language === 'zh-HK') {
                                yearsAndDaysTip = '本站已運行 ' + diffYears + ' 年 ' + diffDays + ' 天';
                            }
                            document.getElementById("sitetime").innerHTML = yearsAndDaysTip;
                        }
                    }
                    calcSiteTime();
                </script>
            
            <br>
            
                <span id="icp">
				<img src="/medias/icp.png"豫ICP备2021025736号
                                    style="vertical-align: text-bottom;"/>
                <a href="https://beian.miit.gov.cn" target="_blank">豫ICP备2021025736号</a>
            </span>
            
        </div>
        <div class="col s12 m4 l4 social-link ">
    <a href="https://github.com/xiaohuixian" class="tooltipped" target="_blank" data-tooltip="visit my GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:1970476603@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=1970476603" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 1970476603" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
				
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>
<div>
<a onclick="switchNightMode()" id="sma" title="模式切换">
    <i class="fa fa-moon-o" id="nightMode" aria-hidden="true"></i>
</a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>
    <script src="/libs/mermaid/mermaid.min.js"></script>

    <!-- Baidu Analytics -->

<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b3593488200a34a873defcaa11fc888a";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    

    

    

    <!--腾讯兔小巢-->
    
        <div style="position:fixed;bottom:125px;right:16px;cursor: pointer;" ID="tuxiaochao">
            <a title="兔小巢" target="_blank" rel="noopener" href="https://support.qq.com/products/348756"><i class="fa fa-comments fa-3x"  aria-hidden="true"></i></a>
        </div>
    
    

    
    
    <script type="text/javascript" size="150" alpha='0.6'
        zIndex="-1" src="/libs/background/ribbon-refresh.min.js" async="async"></script>
    

    
    <script type="text/javascript" src="/libs/background/ribbon-dynamic.js" async="async"></script>
    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    
	<script type="text/javascript">
//	//只在桌面版网页启用特效
	//var windowWidth = $(window).width();
	//if (windowWidth > 768) {
//		document.write('<script type="text/javascript" src="/js/sakura.js"><\/script>');
//	}
	</script>
	
	<script type="text/javascript">
		var OriginTitile=document.title,st;
		document.addEventListener("visibilitychange",function(){ document.hidden?(document.title="ヽ(●-`Д´-)ノ110，有人失踪了",clearTimeout(st)):(document.title="(Ő∀Ő3)ノ失踪人口回归！",st=setTimeout(function(){document.title=OriginTitile},3e3))
		})
	</script>


</body>

</html>
